package com.windfone.web.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.windfone.common.PageUtil;
import com.windfone.common.StringUtil;
import com.windfone.model.Goodsqryorder;
import com.windfone.service.CommonService;

public class PostNotifyAction extends ActionSupport {
	/**	serialVersionUID */
	private static final long serialVersionUID = 1L;
	private CommonService commonService;
	private String currentPage   ;
	private int nextPage;
	private int totalPage;
	private int prevPage;
	private int beginRecord;
	private String qryDay;
	private String qryMonth;
	private String qryYear;
	private List  goodsqryorders;
	public String getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(String currentPage) {
		this.currentPage = currentPage;
	}
	public int getNextPage() {
		return nextPage;
	}
	public void setNextPage(int nextPage) {
		this.nextPage = nextPage;
	}
	public List  getGoodsqryorders() {
		return goodsqryorders;
	}
	public void setGoodsqryorders(List  goodsqryorders) {
		this.goodsqryorders = goodsqryorders;
	}
	public int getTotalPage() {
		return totalPage;
	}
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	public int getPrevPage() {
		return prevPage;
	}
	public void setPrevPage(int prevPage) {
		this.prevPage = prevPage;
	}
	public int getBeginRecord() {
		return beginRecord;
	}
	public void setBeginRecord(int beginRecord) {
		this.beginRecord = beginRecord;
	}
	public String getQryDay() {
		return qryDay;
	}
	public void setQryDay(String qryDay) {
		this.qryDay = qryDay;
	}
	public String getQryMonth() {
		return qryMonth;
	}
	public void setQryMonth(String qryMonth) {
		this.qryMonth = qryMonth;
	}
	public String getQryYear() {
		return qryYear;
	}
	public void setQryYear(String qryYear) {
		this.qryYear = qryYear;
	}
 
	public void setCommonService(CommonService commonService) {
		this.commonService = commonService;
	}
	@Override
	public String execute() throws Exception {
		if ( currentPage == null ||  "".equals( currentPage )){
			currentPage = "1";
		}
		if ( StringUtil.isInteger(  currentPage )){
			String whereCondition = "";
			boolean flag = false;
	 		if ( ( qryDay != null  && qryMonth != null && qryYear !=null ) && 
	 				(!qryDay.equals("0")  &&  !qryMonth.equals("0")) &&  !qryYear.equals("0")  ) {
	 			String dateStr = qryYear + qryMonth + qryDay;
				whereCondition = whereCondition + "  AND  createTime='"+dateStr +"' ";
			} else {
				flag = true;
				whereCondition = "  GROUP by keygroup";
			}
	 
			PageUtil pu = new PageUtil();
			if ( currentPage.equals("0") ){
				currentPage = "1";
			}
			pu.setCurrentPage( Integer.parseInt(  currentPage ));
			if ( flag  ){
				List<Integer> ranges = commonService.getAllGoodsqryorderRecorderNumberFront() ;
				int totalRecords = ranges.size();
				pu.setTotalRecords( totalRecords );
				int pageSize = 3;
				pu.setPageSize(pageSize);
				pu.dealPage();
				int currentPage2 = pu.getCurrentPage();
				nextPage = pu.getNextPage();
				totalPage = pu.getTotalPage();
				prevPage = pu.getPrevPage();
				
				beginRecord = pageSize * (currentPage2 -1);
				if ( beginRecord< 0 )
					beginRecord = 0; 
	 
				if (  ranges.size() > 0 ){
					int[] keys = new int [ ranges.size() ];
					// (currentPage-1)*3 -- currentPage*3  => (1-1)*3=0..3  (2-1)*3=3
					for( int i=(currentPage2-1)*3;i<(currentPage2*3)&& i<keys.length;i++	){
						keys[i] = ranges.get(i);
					}
					if ( keys.length>0)
						goodsqryorders = commonService.listOnePageGoodsqryorder(  keys );
				}
			} else {
				List<Goodsqryorder> allGroups= commonService.getAllKewgroupsByWhere( whereCondition );
				int[] keys = new int [ allGroups.size() ];
				for( int i=0;i<allGroups.size();i++	){
					keys[i] = allGroups.get(i).getKeygroup();
				}
				if ( keys.length >0)
					goodsqryorders = commonService.listOnePageGoodsqryorder(  keys );
			}
			qryDay = "";
			qryMonth = "";
			qryDay = "";
		}
	 
		return SUCCESS;
	}

}
